package com.example.HelloSpace.ui.mission_module;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.example.HelloSpace.R;
import com.example.HelloSpace.utils.MyApp;
import com.google.android.material.imageview.ShapeableImageView;

public class MissionBasicInfoView extends FrameLayout {
    public MissionBasicInfoView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public MissionBasicInfoView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public MissionBasicInfoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public MissionBasicInfoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.view_mission_basic_info, this, true);
        loadMiniTags(findViewById(R.id.mission_basic_info_horizontal_intros));
        loadFlag();
        loadMainImage();
    }

    private void loadMiniTags(LinearLayout container){
        MiniTagView tag=new MiniTagView(getContext());
        tag.setText("发射工位","发射台A");
        container.addView(tag);
        tag=new MiniTagView(getContext());
        tag.setText("目标轨道","亚轨道");
        container.addView(tag);
        tag=new MiniTagView(getContext());
        tag.setText("任务性质","测试飞行");
        container.addView(tag);
        tag=new MiniTagView(getContext());
        tag.setText("发射窗口","06:00\n" +
                "~\n" +
                "07:00");
        container.addView(tag);
        tag=new MiniTagView(getContext());
        tag.setText("助推器编号","B14");
        container.addView(tag);
        tag=new MiniTagView(getContext());
        tag.setText("星舰编号","S33");
        container.addView(tag);

    }
    private void loadFlag(){
        ShapeableImageView flag=this.findViewById(R.id.mission_basic_info_flag);
        Glide.with(flag.getContext())
                .load(URL+"/images/Flags/america.jpeg")
                .into(flag);

    }
    private void loadMainImage(){
        ShapeableImageView image=this.findViewById(R.id.mission_basic_info_main_image);
        Glide.with(image.getContext())
                .load(URL+"/images/entries/Starship.jpg")
                .centerCrop()
                .into(image);

    }
    final String URL= MyApp.getRESOURCE_URL();
}